package com.zplus.managers.petservices.utils;

import com.zplus.managers.petservices.entities.EntityBase;
import java.util.List;
import java.util.Map;

public class Message
{
    // status code
    // 100 - faliure, 200 - success
    private int code;

    // status message, combine to status code
    private String message;

    private Map<String, ? extends EntityBase> contents;
    private List<? extends EntityBase> contentList;

    private Page page;

    public void ok()
    {
        code = 200;
        message = "Operation Complete";
    }

    public void fail()
    {
        code = 100;
        message = "Error Occurence";
    }
    public void fail(String message)
    {
        code = 100;
        this.message = message;
    }

    public Message()
    {
        code = 0;
        message = "";
        contents = null;
        page = null;
    }

    public Message(int code, String message, Map<String,? extends EntityBase > contents, Page p)
    {
        this.code = code;
        this.message = message;
        this.contents = contents;
        this.page = p;
    }

    public int getCode()
    {
        return code;
    }

    public void load(List<? extends EntityBase> lst)
    {
        if(lst == null || lst.size() == 0)
            this.fail();
        else
        {
            this.setContentsList(lst);
            this.ok();
        }
    }

    public void loadPage(Page p)
    {
        if (p.getPageStateInfo() != PageState.NORMAL)
            this.fail();

        this.page = p;
        this.ok();
    }
    public void setCode(int code)
    {
        this.code = code;
    }

    public String getMessage()
    {
        return message;
    }

    public void setMessage(String message)
    {
        this.message = message;
    }

    public Map<String, ? extends EntityBase> getContents()
    {
        return contents;
    }

    public List<? extends EntityBase> getContentList()
    {
        return contentList;
    }
    public void setContents(Map<String, ? extends EntityBase> contents)
    {
        this.contents = contents;
    }
    public void setContentsList(List<? extends EntityBase> contents)
    {
        this.contentList = contents;
    }
    public Page getPage()
    {
        return page;
    }
}
